﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Web.UI;

namespace Vici.Mvc
{
    public class MvcPage : System.Web.UI.Page
    {
        public MvcPage()
        {
            this.EnableViewState = false;
            this.EnableEventValidation = false;
        }

        public override void VerifyRenderingInServerForm(System.Web.UI.Control control)
        {
            //base.VerifyRenderingInServerForm(control);
        }

        public System.Web.UI.Control GetControl(string url)
        {
            return this.LoadControl(url);
        }

        public string GetHTML(string url)
        {
            System.Web.UI.HtmlControls.HtmlForm form = new System.Web.UI.HtmlControls.HtmlForm();
            System.Web.UI.Control control = this.LoadControl(url);
            form.Controls.Add(control);
            this.Controls.Add(form);
            string result = string.Empty;
            using (System.IO.StringWriter sw = new System.IO.StringWriter())
            {
                using (System.Web.UI.HtmlTextWriter htmlW = new System.Web.UI.HtmlTextWriter(sw))
                {
                    this.RenderControl(htmlW);
                }
                result = sw.ToString();
            }
            return result;
        }

        public string RenderControl(System.Web.UI.Control control)
        {
            string result = string.Empty;
            using (System.IO.StringWriter sw = new System.IO.StringWriter())
            {
                using (System.Web.UI.HtmlTextWriter htmlW = new System.Web.UI.HtmlTextWriter(sw))
                {
                    control.RenderControl(htmlW);
                }
                result = sw.ToString();
            }
            return result;
        }
    }
}
